<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu("user")?>


    <h1><?=$this->message("label.header", _User::BUNDLE)?></h1>


    <? /* Breadcrums route & user info display */ ?>
    <?=$this->route(
        $this->message("label.header", _User::BUNDLE), // Route display
        $this->userListForm,                             // ListForm (for user info, see float right)
        $this->users($this->userListForm)->getRows()) // The total amount of users
    ?>


    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->userListForm)?>"
          method="post"
          action="user/list"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            $this->path()."user/edit", // Add New URL
            $this->userListForm,       // ListForm
            array(                     // Filter fields
                UserPeer::USERNAME=>$this->message("prompt.username", _User::BUNDLE),
                UserRolePeer::ROLENAME=>$this->message("prompt.rolename", _User::BUNDLE),
                UserPeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                UserPeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE),
                UserPeer::ACTIVE=>$this->message("choose.active", _Core::BUNDLE),
            ),
            false                      // No languages for this page.
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table class="list" cellspacing="0" cellpadding="0">
        <tr>
            <th class="checkbox"></th>
            <th>
                <?=$this->TH(
                    $this->userListForm,                                     // ListForm
                    UserPeer::USERNAME,                                      // Sort Field
                    $this->message("prompt.username", _User::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->userListForm,                            // ListForm
                    UserPeer::MODIFIED_DATE,                        // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE)  // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->userListForm,                            // ListForm
                    UserPeer::INSERT_DATE,                          // Sort Field
                    $this->message("choose.created", _Core::BUNDLE)   // Header Name
                )?>
            </th>
            <th class="narrow" title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->userListForm,                            // ListForm
                    UserPeer::ACTIVE,                               // Sort Field
                    $this->message("label.active", _Core::BUNDLE)     // Header Name
                )?>
            </th>
            <th class="buttons"></th>
        </tr>

        <? foreach($this->users($this->userListForm)->getItems() as $user) { ?>

            <? /* Display the default language user */ ?>
            <tr class="ctrl">
                <td class="checkbox">

                    <input type="checkbox"
                           name="items[]"
                           value="<?=$user->getUserId()?>"
                           <?=in_array($user->getUserId(), $this->userListForm->getItems()) ? " checked=\"checked\"" : ""?> />

                </td>
                <td><?=$user->getUserName()?></td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$user->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$user->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$user->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$user->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($user->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                </td>
                <td class="buttons">

                    <input type="button"
                           onclick="to('user/edit?user->userId=<?=$user->getUserId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                    <input type="button"
                           onclick="del(<?=$user->getUserId()?>, this.form)"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

        <? } ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->userListForm, // ListForm
            array(               // The actions
                "activate"=>$this->message("choose.activate", _Core::BUNDLE),
                "deactivate"=>$this->message("choose.deactivate", _Core::BUNDLE),
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->userListForm,                            // ListForm
            $this->path()."user/edit",                      // Add New URL
            $this->users($this->userListForm)->getRows() // The total amount of users
        )?>


    </form>

<?=$this->footer("users")?>